namespace Daemon.Service.Contract
{
    using Daemon.Model;
    using Daemon.Model.Entities;
    using Daemon.Data.Infrastructure.FrameWork;
    using Daemon.Data.Infrastructure.Auth;
    using Daemon.Data.Substructure.Framework;
    using Microsoft.EntityFrameworkCore;
    using System.Collections.Generic;
    using System.Linq;
    using System.Linq.Expressions;
    using System;
    public interface IBaseGridService<TEntity, TContext, TIdentity> : IGridAggregateService<TContext>, IService
    where TEntity : class, IGridEntity<TIdentity>, new()
        where TContext : DbContext, new()
    {
        bool IsVerify { set; }

        object Aggregate(
            AggregateItem aggregateItem,
            FilterSet filterSet,
            string gridFilterClause,
            List<int> includeOnlyIds,
            List<int> excludeAnyIds,
            bool? isQuickSearch = false,
            Func<IQueryable<TEntity>, IQueryable<TEntity>> filterFunc = null,
            bool retrievePropertyInfo = false);

        SearchResult<TEntity> Search(
            List<string> fields,
            IEnumerable<ISortItem> sortItems,
            FilterSet filterSet,
            string gridFilterClause,
            List<int> includeOnlyIds,
            List<int> excludeAnyIds,
            int? skip,
            int? take,
            bool? getCount = true,
            bool? isQuickSearch = false,
            Func<IQueryable<TEntity>, IQueryable<TEntity>> filterFunc = null,
            bool? isDistinct = false);

        bool VerifyWhereClause(string gridFilterClause, List<int> excludeAnyIds);

        IQueryable<TEntity> GetFilterRecordByWhereClause(string gridFilterClause, List<int> excludeAnyIds, TContext context);

        string GetClauseFromFilter(FilterSet filterSet);

        SearchResultIds<TIdentity> Ids(IEnumerable<ISortItem> sortItems, FilterSet filterSet, string gridFilterClause, List<int> includeOnlyIds, List<int> excludeAnyIds, List<string> fields, bool? isQuickSearch = false);

        IEnumerable<dynamic> ExtendDataEntities(IQueryable<TEntity> queryable, List<string> fieldNames, DateTime? targetDateTime, FilterSet filterSet, out List<TypeCreator> allTypeCreators);

        int GetCountByAuthInfo(IQueryable<TEntity> queryable, IAuthInfo authInfo, string errorMessage = "");

        IQueryable<TIdentity> FindIdsWithFilters(
            string gridFilterClause,
            List<int> includeOnlyIds,
            List<int> excludeAnyIds,
            FilterSet filterSet,
            TContext context);

        List<BaseStaticFilter<TContext>> GetStaticFilters();

        List<SortItem> GetDefaultSortItems();

        IQueryable<TEntity> GetByFilterClause(string gridFilterClause, TContext context = null);

        IQueryable<TEntity> GetByFilter(int? filterId);
    }

    public interface IBaseGridService<TEntity, TIdentity> : IBaseGridService<TEntity, ApiDBContent, TIdentity>
        where TEntity : class, IGridEntity<TIdentity>, new()
    {
    }

    public interface IBaseGridService<TEntity> : IBaseGridService<TEntity, int>
        where TEntity : class, IGridEntity<int>, new()
    {
    }

    public interface IBaseGridByShortKeyService<TEntity> : IBaseGridService<TEntity, short>
        where TEntity : class, IGridEntity<short>, new()
    {
    }
}